package com.blockmeta.bbs.baselibrary.base.adapter;

import androidx.viewpager.widget.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by author on 2017/12/26.
 * 需要动态创建Fragment
 * 0.1的位置是固定的  标示有自选和排行
 * 之前Fragment是通过 币种和交易所进行创建的
 */

public class BaseViewPager<T extends View> extends PagerAdapter {
    private List<T> views;
    private List<String> tabtitle;

    public BaseViewPager(List<T> views, List<String> tabtitle) {
        this.views = views;
        this.tabtitle = tabtitle;
    }


    @Override
    public int getCount() {
        return views.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = views.get(position);
        container.addView(view, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return tabtitle.get(position % tabtitle.size());
    }
}
